<html>
<head><meta charset="utf-8"><title>How do &quot;bridges&quot; work? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html">How do &quot;bridges&quot; work?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231195629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231195629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231195629">(Mar 21 2021 at 05:46)</a>:</h4>
<p>I'm trying to add a the ability to add a label to a diagnostic in the <code>proc_macro</code> crate, which appears to be possible using the internal <code>rustc_errors::MultiSpan</code> struct. The diagnostic code currently has the ability to add spans to a <code>MultiSpan</code>, but not labels. I can't figure out where the code that even allows the former comes from — the bridge seems quite opaque. What exactly is the purpose of the various "bridges" in the compiler? Perhaps if I understood that, I'd be able to do what I'm trying to do.</p>



<a name="231199221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231199221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231199221">(Mar 21 2021 at 07:17)</a>:</h4>
<p>Alright…I'm pretty sure I figured it out. The compiler led me to the wrong file in the bridge module, so once I found the right one it was straightforward to add the additional method. Still not entirely clear on the purpose of the bridge, but I suppose that's secondary.</p>



<a name="231203116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231203116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231203116">(Mar 21 2021 at 08:50)</a>:</h4>
<p>Admittedly tangential to my original question, but how do I go about using my custom-built <code>proc_macro</code> crate? I'd like to test it before putting a PR up.</p>



<a name="231210509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231210509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231210509">(Mar 21 2021 at 11:29)</a>:</h4>
<p>The bridge is to allow proc-macro compiled from the same source, but by different compilers to be abi compatible. This is necessary for bootstrapping.</p>



<a name="231214879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231214879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231214879">(Mar 21 2021 at 12:56)</a>:</h4>
<p>That hurts my brain <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> how is that possible for them to be abi compatible without repr(C)?</p>



<a name="231214974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231214974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231214974">(Mar 21 2021 at 12:59)</a>:</h4>
<p>It actually does use <code>#[repr(C)]</code> and <code>extern "C"</code> for all types and functions in the bridge. It serializes many proc macro types into a byte buffer.</p>



<a name="231215471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231215471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231215471">(Mar 21 2021 at 13:08)</a>:</h4>
<p>ahhh that makes more sense, thanks!</p>



<a name="231234588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231234588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231234588">(Mar 21 2021 at 19:02)</a>:</h4>
<p>Ah so it's necessary because the libraries are pre-compiled when distributed? That makes sense.</p>
<p>Question still stands on how to use it instead of the built-in one to test it locally? I'd obviously prefer to make sure things work before submitting a PR.</p>



<a name="231234872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231234872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231234872">(Mar 21 2021 at 19:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245610">Jacob Pratt</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20do.20.22bridges.22.20work.3F/near/231234588">said</a>:</p>
<blockquote>
<p>Ah so it's necessary because the libraries are pre-compiled when distributed? That makes sense.</p>
<p>Question still stands on how to use it instead of the built-in one to test it locally? I'd obviously prefer to make sure things work before submitting a PR.</p>
</blockquote>
<p>are you asking for <code>x.py check --stage 1 library/std</code> maybe? that builds <code>proc_macro</code> with the newly built compiler</p>



<a name="231234959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231234959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231234959">(Mar 21 2021 at 19:08)</a>:</h4>
<p>I can <code>check</code> the code and know that it will compile. I'm trying to use it with "normal" code — so I can see the output of the newly implemented diagnostics.</p>



<a name="231234970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231234970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231234970">(Mar 21 2021 at 19:09)</a>:</h4>
<p>I ran <code>./x.py build library/proc_macro</code> but don't even see where it was output.</p>



<a name="231235074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231235074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231235074">(Mar 21 2021 at 19:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245610">Jacob Pratt</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20do.20.22bridges.22.20work.3F/near/231234588">said</a>:</p>
<blockquote>
<p>Ah so it's necessary because the libraries are pre-compiled when distributed? That makes sense.</p>
<p>Question still stands on how to use it instead of the built-in one to test it locally? I'd obviously prefer to make sure things work before submitting a PR.</p>
</blockquote>
<p>I don't know how would you test it, but I would write a UI test, <em>maybe</em> in <a href="https://github.com/rust-lang/rust/tree/HEAD/src/test/ui/proc-macro">https://github.com/rust-lang/rust/tree/HEAD/src/test/ui/proc-macro</a> (I'm not sure about the location).</p>



<a name="231235088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231235088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231235088">(Mar 21 2021 at 19:10)</a>:</h4>
<p>ah you want <a href="https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#creating-a-rustup-toolchain">https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#creating-a-rustup-toolchain</a> then</p>



<a name="231235303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231235303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231235303">(Mar 21 2021 at 19:15)</a>:</h4>
<p>Looking at the UI test directory, I'm not sure that's what I want. I'll look into making a toolchain — that sounds more like what I want. Looks like I need to bootstrap everything myself? This shall be fun <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="231235515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231235515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231235515">(Mar 21 2021 at 19:18)</a>:</h4>
<p>You'll probably need to add a UI test anyways if you want to get this merged</p>



<a name="231235544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231235544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231235544">(Mar 21 2021 at 19:19)</a>:</h4>
<p>Of course. But just to make sure it works at all, playing around by hand will be far simpler. And surprisingly there's not UI tests for the existing implementation there</p>



<a name="231235780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231235780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231235780">(Mar 21 2021 at 19:23)</a>:</h4>
<p>I found this test is related to diagnostics: <a href="https://github.com/rust-lang/rust/blob/f82664191d0e8764b7435b9d72eb0e366b8b1464/src/test/ui/proc-macro/multispan.rs">https://github.com/rust-lang/rust/blob/f82664191d0e8764b7435b9d72eb0e366b8b1464/src/test/ui/proc-macro/multispan.rs</a><br>
To be honest, I think writing a new test like that is actually simpler than creating a custom toolchain...</p>



<a name="231250960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231250960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231250960">(Mar 22 2021 at 00:22)</a>:</h4>
<blockquote>
<p>Ah so it's necessary because the libraries are pre-compiled when distributed? That makes sense.</p>
</blockquote>
<p>I think it's so <code>proc_macro</code> can link to <code>rustc_errors</code> even though proc_macro is compiled by stage1 and rustc_errors is compiled by stage0</p>



<a name="231250979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231250979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231250979">(Mar 22 2021 at 00:23)</a>:</h4>
<p>otherwise you wouldn't be able to build proc-macros with a stage1 toolchain, only stage2, and the compiler has proc macros as dependencies (notably large parts of <code>rustc_query_impl</code> depend on <code>rustc_macros</code>)</p>



<a name="231276962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20%22bridges%22%20work%3F/near/231276962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20.22bridges.22.20work.3F.html#231276962">(Mar 22 2021 at 08:38)</a>:</h4>
<p>Exactly!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>